import java.util.*;
import java.text.*;

/**
 * RecurringBooking keeps an orignal date and then 
 */
public class RecurringBooking extends Booking
{
    private String type;

    /**
     * Do the same initialisation as Booking 
     */
    public RecurringBooking()
    {
        super();
    }

    /**
     * Set the type as either a week or a month
     *
     * @param t String to take either "week" or "month"
     */
    public void setType(String t)
    {
        type = t;
    }

    /**
     * This checks whether the times entered will clash with this booking in
     * the future. The method will stop checking each next week when either
     * a clash is found or the date being updated by 7 is further in the future
     * than the booking wanting to be made
     *
     * @param date1 start date/time of proposed booking
     * @param date2 end date/time of proposed booking
     */
    public boolean week(Date date1, Date date2)
    {
        boolean check = false;

        Calendar newStartDate = Calendar.getInstance();
        Calendar newEndDate = Calendar.getInstance();
        Calendar currentStartDate = Calendar.getInstance();
        Calendar currentEndDate = Calendar.getInstance();

        newStartDate.setTime(date1);
        newEndDate.setTime(date2);
        currentStartDate.setTime(getStartTime());
        currentEndDate.setTime(getEndTime());

        while(true)
        {
            Booking checkBooking = new Booking();
            checkBooking.setStartTime(currentStartDate.getTime());
            checkBooking.setEndTime(currentEndDate.getTime());

            if(checkBooking.isClash(newStartDate.getTime(),newEndDate.getTime()))
            {
                check = true;
                break;
            }

            if(currentStartDate.after(newEndDate))
            {
                break;
            }

            currentStartDate.add(Calendar.DAY_OF_MONTH, 7);
            currentEndDate.add(Calendar.DAY_OF_MONTH, 7);
        }

        return check;
    }
}

